package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cennavi.buss.service.imp.IUserService;
import com.cennavi.minemap.bean.MessageBean;


@RestController
@RequestMapping("/service/user")
public class UserController {

	@Autowired
	private IUserService iUserService;

	@RequestMapping(method = RequestMethod.POST, value = "/login", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean login(@RequestBody String json) {
		return iUserService.login(json);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/register", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean register(@RequestBody String json){
		return iUserService.register(json);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/update", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean update(@RequestBody String json){
		return iUserService.update(json);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean detail(@PathVariable int id){
		return iUserService.detail(id);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/unique", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean uniqueVerify(@RequestBody String json){
		return iUserService.uniqueVerify(json);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/sendVer", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean sendVer(@RequestParam("mail") String mail){
		return iUserService.sendVer(mail);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/verification", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean verification(@RequestBody String json){
		return iUserService.verification(json);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/updatePwd", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean updatePassword(@RequestBody String json){
		return iUserService.updatePassword(json);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/mailboxVeri", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean mailboxVeri(@RequestBody String json){
		return iUserService.mailboxVeri(json);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/role/{userId}", produces="application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryRoleByUserId(@PathVariable int userId) {
		return iUserService.queryRoleByUserId(userId);
	}
	
	
	@RequestMapping(method = RequestMethod.POST, value = "/tencent/register", produces="application/json;charset=UTF-8")
	public @ResponseBody MessageBean tencentRegister(@RequestBody String text) throws Exception {
		return iUserService.tencentRegister(text);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/tencent/login", produces="application/json;charset=UTF-8")
	public @ResponseBody MessageBean tencentLogin(@RequestBody String text) throws Exception {
		return iUserService.tencentLogin(text);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/tencent/verification", produces="application/json;charset=UTF-8")
	public @ResponseBody String tencentVerification(@RequestBody String text) throws Exception {
		return iUserService.tencentVerification(text);
	}
}
